function subVal(val) {
    val = val.substring(0, val.length - 1);
    return val;
}
var standardArray = new Array();
var productID = new Array();
var productPrice = "";
function SetStandardHtml(standardAll, JSHtml) {
    var standardShow = "";
    var ProductState = document.getElementById("ProductState").value;
    if (ProductState == "1") {
        var tempString = "([" + subVal(standardAll) + "])";
        var standardJson = tempString;
        var jsonData = eval(standardJson);
        var sName = "";
        var countStandard = 0;
        for (var i = 0; i < jsonData.length; i++) {
            if (sName == "") {
                countStandard++;
                standardShow += "<dl class='prodl clearfix'><dt>" + jsonData[i].StandardName + "：</dt><dd><ul class='procc' data-property='" + jsonData[i].StandardName + "'>" + "<li id='" + jsonData[i].id + "' title='" + jsonData[i].StandardValueName + "'  onclick='SetCurentStandard(this," + countStandard + ")'>" + jsonData[i].StandardValueName + "</li>";
                sName = jsonData[i].StandardName;
            }
            else if (sName != jsonData[i].StandardName) {
                countStandard++;
                standardShow += "</ul></dd></dl><dl class='prodl clearfix'><dt>" + jsonData[i].StandardName + "：</dt><dd><ul class='procc' data-property='" + jsonData[i].StandardName + "'>" + "<li id='" + jsonData[i].id + "' title='" + jsonData[i].StandardValueName + "'  onclick='SetCurentStandard(this," + countStandard + ")'>" + jsonData[i].StandardValueName + "</li>";
                sName = jsonData[i].StandardName;
            }
            else {
                standardShow += "<li id='" + jsonData[i].id + "' title='" + jsonData[i].StandardValueName + "' onclick='SetCurentStandard(this," + countStandard + ")'>" + jsonData[i].StandardValueName + "</li>";
            }
        }
        standardShow += "</ul></dd></dl>";
        standardShow += JSHtml;
    }
    else {
        standardShow = "<font size='5' color='#995722'>该产品已经下架！</font>";
    }
    document.getElementById("standard").innerHTML = standardShow;
}

function SetCurentStandard(obj, countStandard) {
    var childnodes = obj.parentNode.childNodes;
    for (var k = 0; k < childnodes.length; k++) {
        var lab = childnodes[k].nodeName;
        if (lab == "li" || lab == "Li" || lab == "LI") {
            childnodes[k].className = "";
        }
    }
    obj.className = "likuan";
    standardArray[countStandard] = obj.title.toString();
    productID[countStandard] = obj.id.toString();
    var tempStr = "";
    var tempID = "";
    for (var i = 0; i < standardArray.length; i++) {
        if (typeof (standardArray[i]) != "undefined") {
            if (tempStr == "") {
                tempStr = standardArray[i];
            }
            else {
                tempStr += "," + standardArray[i];
            }
        }
        if (typeof (productID[i]) != "undefined") {
            if (tempID == "") {
                tempID = productID[i];
            }
            else {
                tempID += "," + productID[i];
            }
        }
    }
    document.getElementById("CurentChoice").innerHTML = tempStr;
    document.getElementById("standardIDs").value = tempID;
    $.get("/ajax.aspx?action=getProductDetail", { standard: tempID, pid: document.getElementById("productID").value }, function (data) {
        jsonData = eval("(" + data + ")");
        if (!jsonData.error) {
            $("#productDetailID").val(jsonData.id);
            $("#havenum").html("单价：" + jsonData.price + "元");
            $("#StockNum").val(jsonData.stocknum);
        }
        else {
            $("#productDetailID").val(0);
            $("#havenum").html("单价：--元");
            $("#StockNum").val(0);
        }
    });
}
function GoToBuy() {
    if (!IsNum($("#buynum").val())) {
        alert("请输入正确的购买数量。");
        $("#buynum").focus();
    }
    else {
        if (IsNum($("#productID").val()) && $("#productID").val() != 0) {
            if ($("#ISstandardIDs").val() != "") {
                if (!IsNum($("#productDetailID").val()) && !$("#productDetailID").val() != 0) {
                    alert("请先选择规格。");
                    return
                }
            }
            window.open("/member/OrderAdd.aspx?SaleNumArray=" + $("#buynum").val() + "&ProductIDS=" + $("#productID").val() + "&ProDetailIDS=" + $("#productDetailID").val() + "");
        }
    }
}
function IsNum(str) {
    var value = str;
    if (!(/^(\+|-)?\d+$/.test(value)) || value < 0) {
        return false;
    }
    else {
        return true;
    }
}
function AddToShoppingCart() {
    if (!IsNum($("#buynum").val())) {
        alert("请输入正确的购买数量。");
        $("#buynum").focus();
    }
    else {
        if (IsNum($("#productID").val()) && $("#productID").val() != 0) {
            if ($("#ISstandardIDs").val() != "") {
                if (!IsNum($("#productDetailID").val()) && !$("#productDetailID").val() != 0) {
                    alert("请先选择规格。");
                    return
                }
            }
            $.post("/ajax.aspx?action=AddToShoppingCart", { ProductIDS: $("#productID").val(), ProDetailIDS: $("#productDetailID").val(), BuyCount: $("#buynum").val(), AllCount: $("#StockNum").val(), StockTotalNum: $("#StockTotalNum").val() }, function (data) { jsonData = eval("(" + data + ")"); alert(jsonData.error); });
        }
    }
}
function CheckUserLogin() {
    $.get("/ajax.aspx?action=CheckLogin", function (data) {
        var jsonData = eval("(" + data + ")");
        if (jsonData.CheckResult == "1") {
            $(".LoginInfo").html("您好 '" + jsonData.MemberName + "'，欢迎光临居家！<a class='RedWord' href='/Member/Member.aspx'>会员中心</a> | <a class='RedWord' href='/Member/Logout.aspx'>注销</a>");
        }
        else {
            $(".LoginInfo").html("您好，欢迎光临居家！<a class='RedWord' href='/Member/Login.aspx'>登录</a> | <a class='RedWord' href='/Member/Register.aspx'>注册</a>");
        }
    });
}

function AddToFav(pid) {
    $.get("/ajax.aspx?action=AddToFav", { productID: pid }, function (data) {
        var jsonData = eval("(" + data + ")");
        if (jsonData.CheckResult == "1") {
            alert("添加完成。");
        }
        else {
            alert("添加失败。您当前无权进行此类操作。");
        }
    });
}


function CheckSearchBox(object) {
    if (object.value == '') {
        object.value = '输入产品关键字';
    }
    if (object.value == '输入产品关键字') {
        object.value = '';
    }
}
//大图切换
function SetShopPicHTML(ShowPic) {
    document.getElementById("ShowPic").innerHTML = ShowPic;
}
